//
//  PhotoViewController.m
//  结构
//
//  Created by 看着太阳吃烧饼 on 15/7/23.
//  Copyright (c) 2015年 看着太阳吃烧饼. All rights reserved.
//

#import "PhotoViewController.h"
#import "PhotoCollectionView.h"
#define kwidth [UIScreen mainScreen].bounds.size.width
#define kheight [UIScreen mainScreen].bounds.size.height
@interface PhotoViewController ()

@end

@implementation PhotoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self _createNavition];
    [self _createCollectionView];
    //执行通知
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(hideNav) name:@"HideNavigationBar" object:nil];
    // Do any additional setup after loading the view.
}

- (void)hideNav {
    BOOL isHidden = self.navigationController.navigationBar.isHidden;
    [self.navigationController setNavigationBarHidden:!isHidden animated:YES];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)_createNavition {
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(cancelAction)];
}

- (void)cancelAction {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)_createCollectionView {
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = self.view.bounds.size;
    layout.minimumLineSpacing = 30;
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    _collectionView = [[PhotoCollectionView alloc] initWithFrame:CGRectMake(0, 0, kwidth+30, kheight) collectionViewLayout:layout];
    [self.view addSubview:_collectionView];
    //
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:self.currentIndex inSection:0];
    [_collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionLeft animated:YES];
    
}

- (void)setImageUrlArray:(NSMutableArray *)imageUrlArray {
    _imageUrlArray = imageUrlArray;
    _collectionView.imageUrlArray = _imageUrlArray;
}









/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
